package com.xx.servlte;

import com.xx.entity.Auction;
import com.xx.service.AuctionService;
import com.xx.service.Impl.AuctionServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "ByGetIdServlet",urlPatterns = "/ByGetIdServlet")
public class ByGetIdServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置响应的编码格式
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html; charset=utf-8");
        //获取id
        Integer id = Integer.valueOf(request.getParameter("id"));
        //获取查询条件
        AuctionService servlet = new AuctionServiceImpl();
        Auction auction = servlet.getId(id);
        //保存数据
        request.setAttribute("auction",auction);
        //转发
        request.getRequestDispatcher("Auctions.jsp").forward(request,response);
    }
}
